const express = require('express');
const db = require('../utils/db')

const myRouter = express.Router();

myRouter.post('/post', (req, res) => {
    console.log(req.body)
    res.send({ code: 200, msg: '成功' })
})
myRouter.post('/add', (req, res) => {
    console.log(req.body)
    let { time, money, type, msg, tip } = req.body;

    const sql = `insert into wx values(null,'${time}','${tip}','${msg}',${money},'${type}')`;

    db(sql, function(err, data){
        if (!err) {
            res.send({ code: 200, msg: '添加成功' })
        } else {
            console.log(err)
            res.send({ code: 500, msg: '添加失败' })
        }
    })
})
myRouter.get('/get', (req, res) => {
    console.log(req.query)
    const sql = `select * from wx where time like '${req.query.time}-__' ORDER BY TIME DESC`
    db(sql, function(err, data) {
        if (err) {
            res.send({ code: 500, msg: '查询失败' })
        } else {
            res.send({ code: 200, data })
        }
    })
})
module.exports = myRouter;